package com.jy.adscm.operation.aftersales.controller;


import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.aftersales.bean.ShylMaterialdetail;
import com.jy.adscm.operation.aftersales.service.ShylMaterialdetailService;
import com.jy.adscm.operation.mscyb.bean.JqylMaterialdetail;
import com.jy.adscm.operation.mscyb.service.JqylMaterialdetailService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 原料出库记录 前端控制器
 * </p>
 *
 * @author zyl
 * @since 2019-08-12
 */
@RestController
@RequestMapping("/adscm/operation/aftersales/shylMaterialdetail")
public class ShylMaterialdetailController {
    @Autowired
    ShylMaterialdetailService  shylMaterialdetailService;
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody ShylMaterialdetail shylMaterialdetail, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        boolean insert = shylMaterialdetailService.insertShylMaterialdetail(shylMaterialdetail,token);
        return new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("selectByTid/{tid}")
    public  SimpleCoreResponse  selectByTid(@PathVariable String tid) throws  AdscmSystemException{
        List<ShylMaterialdetail> shylMaterialdetails=new ArrayList<>();
        shylMaterialdetails  = shylMaterialdetailService.selectByTid(tid);
        return  new SimpleCoreResponse("200","查询成功",shylMaterialdetails);
    }
}

